package com.vict.task.bean.dto;

import com.vict.task.core.LocalTaskService;
import lombok.Data;

import java.io.Serializable;
import java.sql.Timestamp;
import java.util.List;

/**
 * 任务
 */
@Data
public class LocalTask implements Serializable {
    private static final long serialVersionUID = -7046166422533590378L;
    /**
     * 执行次数
     */
    private Integer executeCount;
    /**
     * 任务id
     */
    private String taskExecuteInstanceID;

    /**
     * 任务执行器
     */
    private LocalTaskService localTaskService;

    private Timestamp actionTime;

    public LocalTaskConsumeResult commitConsumer(){
        localTaskService.commitConsumer(this.taskExecuteInstanceID);
        LocalTaskConsumeResult localTaskConsumeResult = new LocalTaskConsumeResult();
        localTaskConsumeResult.setResult(LocalTaskConsumeResult.result_commitConsumer);
        return localTaskConsumeResult;
    }

    public LocalTaskConsumeResult commitConsumer(LocalTaskSend sendTask){
        localTaskService.commitConsumer(this.taskExecuteInstanceID, sendTask);
        LocalTaskConsumeResult localTaskConsumeResult = new LocalTaskConsumeResult();
        localTaskConsumeResult.setResult(LocalTaskConsumeResult.result_commitConsumer);
        return localTaskConsumeResult;
    }

    public LocalTaskConsumeResult commitConsumer(List<LocalTaskSend> sendTaskList){
        localTaskService.commitConsumer(this.taskExecuteInstanceID, sendTaskList);
        LocalTaskConsumeResult localTaskConsumeResult = new LocalTaskConsumeResult();
        localTaskConsumeResult.setResult(LocalTaskConsumeResult.result_commitConsumer);
        return localTaskConsumeResult;
    }

    public LocalTaskConsumeResult reconsumeLaterConsumer(){
        LocalTaskConsumeResult localTaskConsumeResult = new LocalTaskConsumeResult();
        localTaskConsumeResult.setResult(LocalTaskConsumeResult.result_reconsumeLaterConsumer);
        return localTaskConsumeResult;
    }

    public LocalTaskConsumeResult failConsumer(){
        LocalTaskConsumeResult localTaskConsumeResult = new LocalTaskConsumeResult();
        localTaskConsumeResult.setResult(LocalTaskConsumeResult.result_failConsumer);
        return localTaskConsumeResult;
    }
}
